package google.sites.view.menus.sites;

import com.google.gdata.util.ServiceException;
import google.sites.model.Kind;
import google.sites.model.Model;
import google.sites.view.View;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Vector;
import dev.tools.view.dialogs.Dialog;

/**
 * Created with IntelliJ IDEA.
 * User: Nuno
 * Date: 02-10-2013
 * Time: 16:31
 */
public class SitesListContentDialog extends Dialog {
    public SitesListContentDialog() {
        super(View.INSTANCE, new BorderLayout());

        final JList<String> list = new JList<>();
        getContentsPanel().add(list);

        final JComboBox<Kind> comboBox = new JComboBox<>(Kind.values());
        comboBox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Kind kind = (Kind) comboBox.getSelectedItem();
                if (kind != null)
                    try {
                        list.setListData(new Vector<>(Model.INSTANCE.getSiteContents(kind)));
                    } catch (IOException | ServiceException e1) {
                        View.showError(e1);
                    }
            }
        });
        getContentsPanel().add(comboBox, BorderLayout.NORTH);
    }
}
